// 加载form模块
let form = layui.form;
//发送ajax请求 渲染文章列表页面
let data = {
    pagenum: 1,
    pagesize: 6,
}
let total;
function article() {
    $.ajax({
        url: '/api/articles',
        data: data,
        success: function (res) {
            // console.log(res);
            total = res.total;
            // 渲染到页面
            let html = template('article', res);
            $('.kr_news_list').html(html);
            // 全部渲染完毕提示
            if (res.data.length >= total) {
                layer.msg('数据已全部加载')
            }
        }
    });

};
article()
//点击加载更多

$('.more').on('click', function () {
    data.pagesize += 6;
    article();
})

// 点击标题跳转到 detail.html
$('.kr_news_list').on('click', '.title', function () {
    location.href = '/web/detail.html'
})

// 时间格式化函数
template.defaults.imports.timer = function (str) {
    let data = new Date(str);
    let y = data.getFullYear();
    let m = n(data.getMonth() + 1);
    let d = n(data.getDate());
    let h = n(data.getHours());
    let mi = n(data.getMinutes());
    let s = n(data.getSeconds());
    return y + '-' + m + '-' + d + ' ' + h + ':' + mi + ':' + s
}
function n(n) {
    return n < 10 ? '0' + n : n
}




